﻿using System;
using System.Data.SqlClient;
using System.Data;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// ReduceRecord 的摘要说明
/// </summary>
namespace Housing
{
    [Serializable]
    public class ReduceRecord
    {
        private int _adjId;
        private string _longid;
        private string _checked;
        private string _nowArea;
        private string _nowMoney;
        private string _nowReduce;
        private string _reduceChange;
        private string _isContinue;
        private string _starttime;
        private string _stopTime;
        private string _remark;
        private string _date;
        private string _renter;
        private string _rentaddress;
        private string _noid;
        private string _reason;

        private int _effectDate;
        public int EffectDate
        {
            get { return _effectDate; }
            set { _effectDate = value; }
        }
        private int _applyid;
        public int Applyid
        {
            get { return _applyid; }
            set { _applyid = value; }
        }

        public ReduceRecord(int adjId)
        {
            GetReduceRecordById(adjId);
        }

        public ReduceRecord()
        {
        }
        public int Adj_id
        {
            get { return _adjId; }
            set { _adjId = value; }
        }

        public string Adj_starttime
        {
            get { return _starttime; }
            set { _starttime = value; }
        }

        public string Adj_longid
        {
            get { return _longid; }
            set { _longid = value; }
        }

        public string Adj_checked
        {
            get { return _checked; }
            set { _checked = value; }
        }

        public string Adj_nowarea
        {
            get { return _nowArea; }
            set { _nowArea = value; }
        }

        public string Adj_nowmoney
        {
            get { return _nowMoney; }
            set { _nowMoney = value; }
        }

        public string Adj_nowreduce
        {
            get { return _nowReduce; }
            set { _nowReduce = value; }
        }

        public string Adj_reducechange
        {
            get { return _reduceChange; }
            set { _reduceChange = value; }
        }

        public string Adj_iscontinue
        {
            get { return _isContinue; }
            set { _isContinue = value; }
        }

        public string Adj_stoptime
        {
            get { return _stopTime; }
            set { _stopTime = value; }
        }

        public string Adj_remark
        {
            get { return _remark; }
            set { _remark = value; }
        }

        public string Adj_date
        {
            get { return _date; }
            set { _date = value; }
        }

        public string Adj_renter
        {
            get { return _renter; }
            set { _renter = value; }
        }

        public string Adj_rentaddress
        {
            get { return _rentaddress; }
            set { _rentaddress = value; }
        }

        public string Adj_noid
        {
            get { return _noid; }
            set { _noid = value; }
        }

        public string Adj_reason
        {
            get { return _reason; }
            set { _reason = value; }
        }

        protected string connString = SqlHelper.ConnectionString;

        public static string getmoneychange(string applyid, string effectDate, string nowmoney)
        {
            string moneychange = "";
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("@applyid", applyid);
            param[1] = new SqlParameter("@EffectDate", effectDate);
            param[2] = new SqlParameter("@nowmoney", nowmoney);
            param[3] = new SqlParameter("@moneychange", SqlDbType.VarChar, 100);
            param[3].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString,CommandType.StoredProcedure,"getReduceChange",param);
            moneychange = param[3].Value.ToString();
            return moneychange;

        }


        //方法
        public void GetReduceRecordById(int adjid)
        {
            string query = "SELECT * FROM ReduceRecord WHERE adj_id=" + adjid;
            SqlDataReader reader = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
            if (reader.Read())
            {
                _adjId = (int)reader[0];
                _longid = reader[1].ToString();
                _checked = reader[2].ToString();
                _nowArea = Utils.GetString(reader[3]);
                _nowMoney = Utils.GetString(reader[4]);
                _nowReduce = Utils.GetString(reader[5]);
                _reduceChange = Utils.GetString(reader[6]);
                _isContinue = reader[7].ToString();
                _starttime = Utils.GetString(reader[8]);
                _stopTime = Utils.GetString(reader[9]);
                _remark = Utils.GetString(reader[10]);
                _date = Utils.GetString(reader[11]);
                _renter = Utils.GetString(reader[12]);
                _rentaddress = Utils.GetString(reader[13]);
                _noid = Utils.GetString(reader[14]);
            }
            reader.Close();
        }

        public bool AddNewReduceRecord(ReduceRecord reducerecord)
        {
            string query = @"INSERT INTO ReduceRecord(adj_longid, adj_checked, adj_nowarea, adj_nowmoney,adj_nowreduce,adj_reducechange,adj_iscontinue,adj_starttime,adj_stoptime,adj_remark,adj_date,adj_renter,adj_rentaddress,adj_noid,applyid,EffectDate) 
                            VALUES('" + reducerecord._longid + "','" + reducerecord._checked + "','" + reducerecord._nowArea + "','" + reducerecord._nowMoney + "','" + reducerecord._nowReduce + "',"
                            + "'" + reducerecord._reduceChange + "','" + reducerecord._isContinue + "','" + reducerecord._starttime + "','" + reducerecord._stopTime + "','" + reducerecord._remark + "','" + reducerecord._date + "',"
                            + "'" + reducerecord._renter + "','" + reducerecord._rentaddress + "','" + reducerecord._noid + "'," + reducerecord.Applyid + "," + reducerecord.EffectDate + ")";
            bool result = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(connString, CommandType.Text, query));
            return result;
        }

        public bool UpdateAReduceRecord(ReduceRecord reducerecord)
        {
            string query = @"UPDATE ReduceRecord SET adj_longid='" + reducerecord._longid + "', adj_checked='" + reducerecord._checked + "',adj_nowarea='" + reducerecord._nowArea + "', adj_nowmoney='" + reducerecord._nowMoney + "',";
            query += "adj_nowreduce='" + reducerecord._nowReduce + "',adj_reducechange='" + reducerecord._reduceChange + "',adj_iscontinue='" + reducerecord._isContinue + "',adj_starttime='"+reducerecord._starttime+"',adj_stoptime";
            query += "='" + reducerecord._stopTime + "',adj_remark='" + reducerecord._remark + "',adj_date='" + reducerecord._date + "',adj_renter='" + reducerecord._renter + "',adj_rentaddress='"+reducerecord._rentaddress+"',adj_noid='"+reducerecord._noid+"' WHERE adj_id=" + reducerecord._adjId;
            bool result=Convert.ToBoolean(SqlHelper.ExecuteNonQuery(connString,CommandType.Text,query));
            return result;
        }
        public bool UpdateAReduceRecordByNoid(ReduceRecord reducerecord)
        {

            string query = @"UPDATE ReduceRecord SET adj_longid='" + reducerecord._longid + "', adj_checked='" + reducerecord._checked + "',adj_nowarea='" + reducerecord._nowArea + "', adj_nowmoney='" + reducerecord._nowMoney + "',";
            query += "adj_nowreduce='" + reducerecord._nowReduce + "',adj_reducechange='" + reducerecord._reduceChange + "',adj_iscontinue='" + reducerecord._isContinue + "',adj_starttime='" + reducerecord._starttime + "',adj_stoptime";
            query += "='" + reducerecord._stopTime + "',adj_remark='" + reducerecord._remark + "',adj_date='" + reducerecord._date + "',adj_renter='" + reducerecord._renter + "',adj_rentaddress='" + reducerecord._rentaddress + "',adj_noid='" + reducerecord._noid + "' WHERE [adj_noid]=" + reducerecord._noid + "  and  adj_id=(select top 1 adj_id from [ReduceRecord] where [adj_noid]=" + reducerecord._noid + " order by adj_id desc)";
            bool result = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(connString, CommandType.Text, query));
            return result;
        }

        public bool DeleteAReduceRecord(int adjid)
        {
            string query = "DELETE FROM ReduceRecord WHERE adj_id=" + adjid;
            bool result = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(connString,CommandType.Text,query));
            return result;
        }
        public static bool DeleteAReduceRecordByApplyid(string applyid)
        {
            string query = "DELETE FROM ReduceRecord WHERE applyid=" + applyid;
            bool result = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, query));
            return result;
        }

        public void GetNewestReduceRecordBynoid(string noid)
        {
            string query = "SELECT TOP 1 * FROM ReduceRecord WHERE adj_noid=" + noid + " AND adj_checked=1 ORDER BY adj_id DESC";
            SqlDataReader reader = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
            if (reader.Read())
            {
                _adjId = (int)reader[0];
                _longid = reader[1].ToString();
                _checked = reader[2].ToString();
                _nowArea = Utils.GetString(reader[3]);
                _nowMoney = Utils.GetString(reader[4]);
                _nowReduce = Utils.GetString(reader[5]);
                _reduceChange = Utils.GetString(reader[6]);
                _isContinue = reader[7].ToString();
                _starttime = Utils.GetString(reader[8]);
                _stopTime = Utils.GetString(reader[9]);
                _remark = Utils.GetString(reader[10]);
                _date = Utils.GetString(reader[11]);
                _renter = Utils.GetString(reader[12]);
                _rentaddress = Utils.GetString(reader[13]);
                _noid = Utils.GetString(reader[14]);
            }
            reader.Close();
        }

        public void GetNewestReduceRecordByApplyid(string applyid)
        {
            string query = "SELECT TOP 1 * FROM ReduceRecord WHERE applyid=" + applyid + " ORDER BY adj_id DESC";
            SqlDataReader reader = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
            if (reader.Read())
            {
                _adjId = (int)reader[0];
                _longid = reader[1].ToString();
                _checked = reader[2].ToString();
                _nowArea = Utils.GetString(reader[3]);
                _nowMoney = Utils.GetString(reader[4]);
                _nowReduce = Utils.GetString(reader[5]);
                _reduceChange = Utils.GetString(reader[6]);
                _isContinue = reader[7].ToString();
                _starttime = Utils.GetString(reader[8]);
                _stopTime = Utils.GetString(reader[9]);
                _remark = Utils.GetString(reader[10]);
                _date = Utils.GetString(reader[11]);
                _renter = Utils.GetString(reader[12]);
                _rentaddress = Utils.GetString(reader[13]);
                _noid = Utils.GetString(reader[14]);
            }
            reader.Close();
        }

        public void GetIfContinueThisMonth(string longid)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            string query = "SELECT TOP 1 * FROM ReduceRecord WHERE adj_longid='" + longid + "' AND adj_iscontinue=1 AND adj_date=" + time + " ORDER BY adj_id DESC";
            SqlDataReader dr = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
            if (dr.Read())
            {
                _adjId = (int)dr[0];
                _longid = dr[1].ToString();
                _checked = dr[2].ToString();
                _nowArea = Utils.GetString(dr[3]);
                _nowMoney = Utils.GetString(dr[4]);
                _nowReduce = Utils.GetString(dr[5]);
                _reduceChange = Utils.GetString(dr[6]);
                _isContinue = dr[7].ToString();
                _starttime = Utils.GetString(dr[8]);
                _stopTime = Utils.GetString(dr[9]);
                _remark = Utils.GetString(dr[10]);
                _date = Utils.GetString(dr[11]);
                _renter = Utils.GetString(dr[12]);
                _rentaddress = Utils.GetString(dr[13]);
                _noid = Utils.GetString(dr[14]);
            }
            dr.Close();
        }

        public void GetIfChangedThisMonth(string longid)
        {
            DateTime dt = DateTime.Now;
            dt = dt.AddMonths(1);
            int time = dt.Year * 100 + dt.Month;
            string query = "SELECT TOP 1 * FROM ReduceRecord WHERE adj_longid='" + longid + "' AND adj_iscontinue=0 AND adj_date=" + time + " ORDER BY adj_id DESC";
            SqlDataReader dr = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
            if (dr.Read())
            {
                _adjId = (int)dr[0];
                _longid = dr[1].ToString();
                _checked = dr[2].ToString();
                _nowArea = Utils.GetString(dr[3]);
                _nowMoney = Utils.GetString(dr[4]);
                _nowReduce = Utils.GetString(dr[5]);
                _reduceChange = Utils.GetString(dr[6]);
                _isContinue = dr[7].ToString();
                _starttime = Utils.GetString(dr[8]);
                _stopTime = Utils.GetString(dr[9]);
                _remark = Utils.GetString(dr[10]);
                _date = Utils.GetString(dr[11]);
                _renter = Utils.GetString(dr[12]);
                _rentaddress = Utils.GetString(dr[13]);
                _noid = Utils.GetString(dr[14]);
            }
            dr.Close();
        }
        
        /// 租金减免调整(增加、减少)(申请)
        public bool ChangeReduceOprate(string longid,string noid, string renter, string rentaddress, string nowmoney, string nowarea,
                                        string nowreduce, string oldreduce, string oldstoptime, string remark, string reason)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            DateTime dt = DateTime.Now.AddMonths(1);
            int starttime = dt.Year * 100 + dt.Month;
            ReduceRecord reduce = new ReduceRecord();
            reduce.GetIfChangedThisMonth(longid);
            if (reduce.Adj_iscontinue == "0")
            {
                if (reduce.Adj_checked == "1")
                {
                    reduce.Adj_checked = "0";
                    reduce.Adj_date = time.ToString();
                    reduce.Adj_iscontinue = "0";
                    reduce.Adj_longid = longid;
                    reduce.Adj_noid = noid;
                    reduce.Adj_nowarea = nowarea;
                    reduce.Adj_nowmoney = nowmoney;
                    reduce.Adj_nowreduce = nowreduce;
                    reduce.Adj_reducechange = (float.Parse(nowreduce) - float.Parse(oldreduce)).ToString();
                    reduce.Adj_remark = remark;
                    reduce.Adj_rentaddress = rentaddress;
                    reduce.Adj_renter = renter;
                    reduce.Adj_starttime = starttime.ToString();
                    reduce.Adj_stoptime = oldstoptime;
                    reduce.AddNewReduceRecord(reduce);
                }
                else
                {
                    reduce.Adj_nowarea = nowarea;
                    reduce.Adj_nowmoney = nowmoney;
                    reduce.Adj_nowreduce = nowreduce;
                    reduce.Adj_reducechange = (float.Parse(nowreduce) - float.Parse(oldreduce)).ToString();
                    reduce.Adj_remark = remark;
                    reduce.Adj_rentaddress = rentaddress;
                    reduce.Adj_renter = renter;
                    reduce.Adj_date = time.ToString();
                    reduce.Adj_reason = reason;
                    reduce.UpdateAReduceRecord(reduce);
                }
            }
            else
            {
                reduce.Adj_checked = "0";
                reduce.Adj_date = time.ToString();
                reduce.Adj_iscontinue = "0";
                reduce.Adj_longid = longid;
                reduce.Adj_noid = noid;
                reduce.Adj_nowarea = nowarea;
                reduce.Adj_nowmoney = nowmoney;
                reduce.Adj_nowreduce = nowreduce;
                reduce.Adj_reducechange = (float.Parse(nowreduce)-float.Parse(oldreduce)).ToString();
                reduce.Adj_remark = remark;
                reduce.Adj_rentaddress = rentaddress;
                reduce.Adj_renter = renter;
                reduce.Adj_reason = reason;
                reduce.Adj_starttime = starttime.ToString();
                reduce.Adj_stoptime = oldstoptime;
                reduce.AddNewReduceRecord(reduce);
            }
            return true;
        }

        /// 获取租金减免调整信息
        public DataSet GetReduceChanges(string street)
        {
            DateTime dt = DateTime.Now;
            dt = dt.AddMonths(1);
            int time = dt.Year * 100 + dt.Month;
            string query = "";
            if (street == "海曙")
                query = @"SELECT A.apply_name,A.apply_address,A.apply_time,A.apply_longid,R.adj_id,A.apply_noid FROM Apply AS A INNER JOIN ReduceRecord AS R ON A.apply_longid=R.adj_longid "
                        + "WHERE R.adj_checked=0 AND R.adj_iscontinue=0 AND R.adj_date=" + time + " AND A.apply_id "
                        + "IN (SELECT TOP 1 apply_id FROM Apply WHERE apply_updchecked=1 AND apply_longid=A.apply_longid ORDER BY apply_id DESC)";
            else
                query = @"SELECT A.apply_name,A.apply_address,A.apply_time,A.apply_longid,R.adj_id,A.apply_noid FROM Apply AS A INNER JOIN ReduceRecord AS R ON A.apply_longid=R.adj_longid "
                        + "WHERE R.adj_checked=0 AND R.adj_iscontinue=0 AND R.adj_date=" + time + " AND A.apply_id "
                        + "IN (SELECT TOP 1 apply_id FROM Apply WHERE apply_updchecked=1 AND apply_longid=A.apply_longid AND apply_street='" + street + "' ORDER BY apply_id DESC)";
            DataSet ds = SqlHelper.ExecuteDataset(connString, CommandType.Text, query);
            return ds;
        }

        /// 通过----租金减免调整申请
        public bool SetReduceChangePass(string longid, int adjid)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            ReduceRecord reduce = new ReduceRecord(adjid);
            //判断本月是否有已审核通过的历史记录
            string query = "SELECT TOP 1 adj_id FROM ReduceRecord WHERE adj_checked=1 AND adj_longid='" + longid + "' AND adj_date=" + time + " ORDER BY adj_id DESC";
            int ID = SqlHelper.ExecuteNonQuery(connString, CommandType.Text, query);
            if (ID > 0)
            {
                //本月有记录则删除原记录，标记新纪录为通过
                SqlConnection conn = new SqlConnection(connString);
                conn.Open();
                SqlTransaction transaction = conn.BeginTransaction();
                try
                {
                    query = "DELETE FROM ReduceRecord WHERE adj_id=" + ID;
                    SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, query, null);
                    string cmdtext = "UPDATE ReduceRecord SET adj_checked=1 WHERE adj_id=" + adjid;
                    SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, cmdtext, null);
                    transaction.Commit();
                    return true;
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return false;
                }
            }
            else
            {
                //本月没有记录则标记新纪录为通过
                reduce.GetReduceRecordById(adjid);
                reduce.Adj_checked = "1";
                return reduce.UpdateAReduceRecord(reduce);
            } 
        }

        /// 否决----租金减免调整申请
        public bool SetReduceChangeUnPass(int adjid)
        {
            ReduceRecord reduce = new ReduceRecord();
            return reduce.DeleteAReduceRecord(adjid);
        }

        /// 租金减免续办(申请)
        public bool ContinueReduceOprate(string longid,string noid, string stoptime, string remark,string reason)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            DateTime dt = DateTime.Now.AddMonths(1);
            int starttime = dt.Year * 100 + dt.Month;
            ReduceRecord reduce = new ReduceRecord();
            reduce.GetIfContinueThisMonth(longid);
            if (reduce.Adj_iscontinue == "1")
            {
                if (reduce.Adj_checked == "1")
                {
                    reduce.Adj_checked = "0";
                    reduce.Adj_date = time.ToString();
                    reduce.Adj_iscontinue = "1";
                    //reduce.Adj_longid = longid;
                    //reduce.Adj_noid = noid;
                    //reduce.Adj_nowarea = "";
                    //reduce.Adj_nowmoney = "";
                    //reduce.Adj_nowreduce = "";
                    //reduce.Adj_reducechange = "";
                    reduce.Adj_remark = remark;
                    //reduce.Adj_rentaddress = "";
                    //reduce.Adj_renter = "";
                    reduce.Adj_starttime = starttime.ToString();
                    reduce.Adj_stoptime = stoptime;
                    reduce.Adj_reason = reason;
                    reduce.AddNewReduceRecord(reduce);
                }
                else
                {
                    reduce.Adj_remark = remark;
                    reduce.Adj_starttime = starttime.ToString();
                    reduce.Adj_stoptime = stoptime;
                    reduce.Adj_reason = reason;
                    reduce.UpdateAReduceRecord(reduce);
                }
                return true;
            }
            else
            {
                //若本月还没有续办申请，读取该用户最新实物配租信息并添加新纪录
                string query = "SELECT TOP 1 * FROM ReduceRecord WHERE adj_longid='" + longid + "' AND adj_checked=1";
                SqlDataReader dr = SqlHelper.ExecuteReader(connString, CommandType.Text, query);
                if (dr.Read())
                {
                    reduce.Adj_checked = "0";//
                    reduce.Adj_date = time.ToString();//
                    reduce.Adj_iscontinue = "1";//
                    reduce.Adj_reducechange = dr["adj_reducechange"].ToString();//
                    reduce.Adj_longid = longid;//
                    reduce.Adj_noid = noid;//
                    reduce.Adj_nowarea = dr["adj_nowarea"].ToString();//
                    reduce.Adj_nowmoney = dr["adj_nowmoney"].ToString();//
                    reduce.Adj_remark = remark;//
                    reduce.Adj_reason = reason;//
                    reduce.Adj_starttime = starttime.ToString();//
                    reduce.Adj_stoptime = stoptime;//
                    reduce.Adj_nowreduce = dr["adj_nowreduce"].ToString();//
                    reduce.Adj_renter = dr["adj_renter"].ToString();
                    reduce.Adj_rentaddress = dr["adj_rentaddress"].ToString();
                    dr.Close();
                    return reduce.AddNewReduceRecord(reduce);
                }
                else
                    return false;
            }
        }

        /// 获取租金减免续办信息
        public DataSet GetReduceContinues(string street)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            string query = "";
            if(street=="海曙")
                query = @"SELECT A.apply_name,A.apply_address,A.apply_time,R.adj_id,A.apply_longid,R.adj_stoptime,R.adj_remark,R.adj_reason FROM Apply AS A "
                        + "INNER JOIN ReduceRecord AS R ON A.apply_longid=R.adj_longid WHERE R.adj_checked=0 AND R.adj_iscontinue=1 AND R.adj_date=" + time + " AND A.apply_id "
                        +"IN (SELECT TOP 1 apply_id FROM Apply WHERE apply_updchecked=1 AND apply_longid=A.apply_longid ORDER BY apply_id DESC)";
            else
                query = @"SELECT A.apply_name,A.apply_address,A.apply_time,R.adj_id,A.apply_longid,R.adj_stoptime,R.adj_remark,R.adj_reason FROM Apply AS A "
                        + "INNER JOIN ReduceRecord AS R ON A.apply_longid=R.adj_longid WHERE R.adj_checked=0 AND R.adj_iscontinue=1 AND R.adj_date=" + time + " AND A.apply_id "
                        + "IN (SELECT TOP 1 apply_id FROM Apply WHERE apply_updchecked=1 AND apply_longid=A.apply_longid AND apply_street='"+street+"' ORDER BY apply_id DESC)";
            DataSet ds = SqlHelper.ExecuteDataset(connString, CommandType.Text, query);
            return ds;
        }
   
        /// 通过----租金减免续办申请
        public bool SetReduceContinuePass(string longid, int adjid)
        {
            int time = DateTime.Now.Year * 100 + DateTime.Now.Month;
            DateTime dt = DateTime.Now.AddMonths(1);
            int nextmonth = dt.Year * 100 + dt.Month;
            ReduceRecord reduce = new ReduceRecord(adjid);
            //判断本月是否有已审核通过的历史记录
            string query = "SELECT TOP 1 adj_id FROM ReduceRecord WHERE adj_checked=1 AND adj_longid='" + longid + "' AND adj_date=" + time + " ORDER BY adj_id DESC";
            int ID = SqlHelper.ExecuteNonQuery(connString, CommandType.Text, query);
            if (ID > 0)
            {
                //本月有记录则删除旧记录，更新新纪录
                SqlConnection conn = new SqlConnection(connString);
                conn.Open();
                SqlTransaction transaction = conn.BeginTransaction();
                try
                {
                    query = "DELETE FROM ReduceRecord WHERE adj_id=" + ID;
                    SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, query, null);
                    string cmdtext = "UPDATE ReduceRecord SET adj_checked=1 WHERE adj_id=" + adjid;
                    SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, cmdtext, null);
                    transaction.Commit();
                    return true;
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return false;
                }
            }
            else
            {
                //本月没有记录则标记新纪录为通过
                reduce.GetReduceRecordById(adjid);
                reduce.Adj_checked = "1";
                return reduce.UpdateAReduceRecord(reduce);
            } 
        }

        /// 否决----租金减免续办申请
        public bool SetReduceContinueUnPass(int adjid)
        {
            ReduceRecord reduce = new ReduceRecord();
            return reduce.DeleteAReduceRecord(adjid);
        }
    }
}